import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
// import { Plugin as importToCDN } from 'vite-plugin-cdn-import'

import { visualizer } from 'rollup-plugin-visualizer'
import externalGlobals from 'rollup-plugin-external-globals'

// https://vitejs.dev/config/
export default defineConfig({
  base: './', // 打包出来资源文件加载的路径
  plugins: [
    react(),
    visualizer({ open: true })
    // importToCDN({
    //   modules: [
    //     {
    //       name: 'react',
    //       var: 'React',
    //       path: 'https://unpkg.com/react@18.2.0/umd/react.production.min.js'
    //     },
    //     {
    //       name: 'echarts',
    //       var: 'echarts',
    //       path: 'https://unpkg.com/echarts@5.4.2'
    //     },
    //     {
    //       name: '@wangeditor/editor',
    //       var: 'wangEditor',
    //       path: 'https://unpkg.com/@wangeditor/editor@latest/dist/index.js',
    //       css: 'https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css'
    //     }
    //   ]
    // })
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src') // 路径别名
    }
  },
  build: {
    rollupOptions: {
      external: ['react', 'echarts', '@wangeditor/editor'],
      plugins: [
        externalGlobals({
          react: 'React',
          echarts: 'echarts',
          '@wangeditor/editor': 'wangEditor'
        })
      ]
    }
  }
})
